package com.jjkj.environmental.environmental.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.widget.EditText
import com.jjkj.environmental.environmental.R

@SuppressLint("InflateParams")
class EdtDialog(context: Context, onChoose: OnChoose, type: Int) {
    private var alertDialog: AlertDialog
    private var content: String

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.login_dialog_view, null)
        val edt = view.findViewById<EditText>(R.id.edt_content)
        content = ""
        alertDialog = AlertDialog.Builder(context)
                .setTitle("请输入要修改的值")
                .setView(view)
                .setNegativeButton("取消") { _, _ -> this.cancel() }
                .setPositiveButton("确认") { _, _ ->
                    onChoose.choose(edt.text.toString(), type)
                }
                .create()
    }

    fun show() {
        if (!alertDialog.isShowing) {
            alertDialog.show()
        }
    }

    private fun cancel() {
        if (alertDialog.isShowing) {
            alertDialog.cancel()
        }
    }

    interface OnChoose {
        fun choose(content: String, type: Int)
    }
}